<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>车抵贷（YQ）手动扣款</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">客户</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">合同号</div>
                    <div class="field">
                        <input name="contNo" id="contNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">扣款支付表号</div>
                    <div class="field">
                        <input name="cutPaySchNo" id="cutPaySchNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">放款时间</div>
                    <div class="field">
                        <input ligerui="width: 100" name="actPayTmBg" id="actPayTmBg" type="text" class="ui-datepicker" value="">
                        -
                        <input ligerui="width: 100" name="actPayTmEd" id="actPayTmEd" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                </div>
                <div class="clearFix"></div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>
<script type="text/javascript">
    var grid = null, form = null;
    $(function () {
        initGrid();
        /* 查询 */
        $("#searchBtn").click(function (event) {
            form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
            //detailGrid.reload();
        });
        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });
    });

    /* 初始化列表*/
    function initGrid(){
        var url = '<%=path%>/capital/capPayInfo/initCddYqCutPayList.do';
        grid = $("#ligergrid1").ligerGrid({
                url:url,
                method: 'get',
                columns: [
                    {display: '合同号', name: 'contNo', minWidth: 140 , enabledSort:true},
                    {display: '客户名称', name: 'cstNm', minWidth: 100,align:'center', enabledSort:true},
                    {display: '客户经理', name: 'cstMgrNm', width: 100, align: 'center', enabledSort: false},
                    {display: '所属事业部', name: 'buOrgCdNm', width: 100, align: 'center', enabledSort: false},
                    {display: 'YQ支付表号', name: 'paySchNo', minWidth: 160,align:'center', enabledSort:true},
                    {display: '放款状态', name: 'payStsCdNm', minWidth: 100,align:'center', enabledSort:true},
                    {display: '实际放款金额', name: 'actPayAmt', width: 100, align: 'right', enabledSort: false,
                        render:function(rowdata,index,value){
                            if(rowdata.actPayAmt){
                                return '&yen;'+FormatMoney(rowdata.actPayAmt/100);
                            }
                        }
                    },
                    {display: '实际放款时间', name: 'actPayTm', minWidth: 100 , render:renderDate, enabledSort:true},
                    {display: '扣款支付表号', name: 'cutPaySchNo', width: 160, enabledSort:true},
                    {display: '扣款状态', name: 'cutPayStsCd', minWidth: 100,align:'center',
                        render: function (rowdata, rowindex, value, column) {
                            if(value == '0'){
                                return '失败';
                            }else if(value == '1'){
                                return '成功';
                            }else if(value == '2'){
                                return '未支付';
                            }else if(value == '3'){
                                return '处理中';
                            }else if(value == '4'){
                                return '已手动还款';
                            }
                            return '';
                        },
                        enabledSort:true},
                    {display: '扣款结果', name: 'resultesc', width: 120, enabledSort:true},
                    {display: '银行名称', name: 'payerBkNm', width: 120, enabledSort:true},
                    {display: '实际扣款金额', name: 'cutActPayAmt', width: 100, align: 'right', enabledSort: false,
                        render:function(rowdata,index,value){
                            if(rowdata.cutActPayAmt){
                                return '&yen;'+FormatMoney(rowdata.cutActPayAmt);
                            }
                        }
                    },
                    {display: '申请扣款时间', name: 'yqApplyDate', minWidth: 140 , render:renderDateDetail, enabledSort:true},
                    {display: '操作',minWidth: 120,align:'left',
                        render: function (rowdata, rowindex, value){
                            var j="";
                            if(rowdata.cutPayStsCd == "2" || rowdata.cutPayStsCd == "3" || rowdata.cutPayStsCd == "0"){
                                j+='<a class="sq-button-hasicon" href="javascript:updateCutPayStsCd(';
                                j+="'"+rowdata.cutPaySchNo+"',";
                                j+="'"+rowdata.paySchNo+"',";
                                j+="'"+rowdata.cstId+"',";
                                j+="'"+rowindex+"'";
                                j+=')">刷新扣款状态</a>';
                            }
                            return j;
                        }
                    }
                ],
                pageSize: 10,
                root: 'rows',
                record: 'total',
                hideLoadButton: true,
                width: '100%',
                height: '100%',
                heightDiff: -2,
                allowUnSelectRow: true,
                alternatingRow: false,
                rownumbers: false,  //显示序号
                onBeforeShowData: function () {
                    var grid = this;
                    grid.collapsedRows = [];
                },
            })
        grid.setHeight(100);
        form = $("#searchBar").ligerForm();
    }

    //确认扣款
    function confirmCutPay(id,cstId,cutPaySchNo,paySchId,paySchNo) {
        confirmCutPayDialog ("点击确认扣款按钮将不可取消，请谨慎操作！", '扣款确认', function (flag) {
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data:{id:id,cstId:cstId,cutPaySchNo:cutPaySchNo,paySchId:paySchId,paySchNo:paySchNo},
                async:false,
                url: '<%=path%>/capital/capPayInfo/confirmCutPay.do',
                beforeSend: function(){
                    wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                },
                success:function(msg){
                    wait_dialog.close();
                    if(msg.success == 1){
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                        grid.reload();
                    }else{
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                    }
                }
            });
        }, $.ligerDefaults.ButtonStrings.yes);
    }

    // 自定义按钮文本
    $.ligerDefaults.ButtonStrings = {
        yes: '确认扣款',
    };
    // 自定义按钮的弹出框
    function confirmCutPayDialog (content, title, callback, left)
    {
        if (typeof (title) == "function")
        {
            callback = title;
            type = null;
        }
        var btnclick = function (item, Dialog)
        {
            Dialog.close();
            if (callback)
            {
                callback(item.type == 'ok');
            }
        };
        p = {
            type: 'question',
            content: content,
            buttons: [
                {
                    text: left, onclick: btnclick, type: 'ok', cls: 'l-dialog-btn-ok'
                }
            ]
        };
        if (typeof (title) == "string" && title != "") p.title = title;
        $.extend(p, {
            showMax: false,
            showToggle: false,
            showMin: false,
            width: 300,
            height: 100
        });
        return $.ligerDialog(p);
    };

    //格式化时间
    function renderDate(rowdata, index, value){
        var dateStr = "";
        if(null != value){
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    //格式化时间
    function renderDateDetail(rowdata, index, value){
        var dateStr = "";
        if(null != value){
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    //刷新扣款状态
    function updateCutPayStsCd(cutPaySchNo,paySchNo,cstId,rowindex) {
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data:{cutPaySchNo:cutPaySchNo,paySchNo:paySchNo,cstId:cstId},
            async:false,
            url: '<%=path%>/capital/capPayInfo/refreshCutPayStsCd.do',
            beforeSend: function(){
                wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
            },
            success:function(msg){
                wait_dialog.close();
                if(msg.success == 1){
                    if (null !=msg.data){
                        if(null != msg.data.payStsCd){
                            grid.updateCell("cutPayStsCd", msg.data.payStsCd, rowindex);
                        }
                        if( null != msg.data.paymentMoney){
                            grid.updateCell("cutActPayAmt", msg.data.paymentMoney, rowindex);
                        }
                        if( null != msg.data.crtDate){
                            grid.updateCell("yqApplyDate", msg.data.crtDate, rowindex);
                        }
                        if( null != msg.data.resultesc){
                            grid.updateCell("resultesc", msg.data.resultesc, rowindex);
                        }
                    }
                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                }else{
                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                }
            }
        });
    }

</script>

</body>
</html>
